using UnityEngine;

public class NodeMouseEvent : UIWidgetContainer
{
    static public NodeMouseEvent Set(UIWidget widget, WXB.RenderNode.NodeBase node)
    {
        NGUITools.AddWidgetCollider(widget.gameObject);
        NodeMouseEvent nme = widget.gameObject.GetComponent<NodeMouseEvent>();
        if (nme == null)
            nme = widget.gameObject.AddComponent<NodeMouseEvent>();

        nme.mWidget = widget;
        nme.mNodeBase = node;
        node.UIWidgetList.Add(widget);

        return nme;
    }

    public UIWidget mWidget;
    public WXB.RenderNode.NodeBase mNodeBase;

    bool mMouseEnter = false;
    void Update()
    {
        if (UICamera.hoveredObject == gameObject)
        {
            if (mMouseEnter == false)
            {
                mMouseEnter = true;
                mNodeBase.onMouseEnter();
            }
        }
        else if (mMouseEnter == true)
        {
            mMouseEnter = false;
            mNodeBase.onMouseLeave();
        }
    }

    void OnClick()
    {
        transform.parent.gameObject.SendMessage("OnNodeClick", mNodeBase);
    }
}